package com.gitee.lw114514.tliasweb.mapper;

import com.gitee.lw114514.tliasweb.pojo.Emp;
import com.gitee.lw114514.tliasweb.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/*
 * 用于操作员工信息
 */
@Mapper
public interface EmpMapper {
//    /*
//     * 查询符合条件的总记录数
//     */
//    @Select("SELECT COUNT(*) FROM emp e LEFT JOIN dept d ON e.dept_id = d.id")
//    public Integer count();
//
//    /*
//     * 分页查询员工信息
//     */
//    @Select("SELECT e.*, d.name deptName FROM emp e LEFT JOIN dept d ON e.dept_id = d.id " +
//            "ORDER BY e.update_time DESC LIMIT #{start}, #{pageSize}")
//    public List<Emp> list(Integer start, Integer pageSize);


    /*
     * 分页查询员工信息
     */
//    @Select("SELECT e.*, d.name deptName FROM emp e LEFT JOIN dept d ON e.dept_id = d.id " +
//            "WHERE e.name LIKE '%%' && gender = #{} && entry_date BETWEEN #{} AND #{} " +
//            "ORDER BY e.update_time DESC")
    List<Emp> list(EmpQueryParam empQueryParam);

    /*
     * 添加员工信息
     */
    @Options(useGeneratedKeys = true, keyProperty = "id") //获取到生成的主键值，并且设置给emp对象--主键返回
    @Insert("INSERT INTO emp(username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) "
            + "VALUES(#{username}, #{password}, #{name}, #{gender}, #{phone}, #{job}, #{salary}, #{image}, #{entryDate}, #{deptId}, #{createTime}, #{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getInfo(Integer id);

    void updateById(Emp emp);

    /*
     * 查询员工工作信息
     */
    @MapKey("pos")
    List<Map<String, Object>> countEmpJobData();

    @MapKey("name")
    List<Map<String, Object>> countEmpGenderData();

    Emp selectByUsernameAndPassword(Emp emp);

    List<Emp> listAll();
}
